﻿using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wpf.Netdisk.Events;
using Wpf.Netdisk.Models.Event;

namespace Wpf.Netdisk.Extensions
{
    public static class DialogExtensions
    {
        /// <summary>
        /// 推送等待消息
        /// </summary>
        /// <param name="aggregator"></param>
        /// <param name="model"></param>
        public static void UpdateLoading(this IEventAggregator aggregator, UpdateModel model)
        {
            aggregator.GetEvent<UpdateLoadingEvent>().Publish(model);
        }
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="eventAggregator"></param>
        /// <param name="action"></param>
        public static void SendMessage(this IEventAggregator eventAggregator, string message, string filterName = "Main")
        {
            eventAggregator.GetEvent<MessageEvent>().Publish(new MessageModel
            {
                Message = message,
                Filter = filterName
            });
        }
        /// <summary>
        /// 注册提示消息事件
        /// </summary>
        /// <param name="eventAggregator"></param>
        /// <param name="action"></param>
        public static void ResgisterMessage(this IEventAggregator eventAggregator, Action<MessageModel> action, string filterName = "Main")
        {
            eventAggregator.GetEvent<MessageEvent>().Subscribe(action, ThreadOption.PublisherThread, true, m =>
            {
                return m.Filter.Equals(filterName);
            });
        }
    }
}
